﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows;

namespace Common.ViewModels
{
    public class VisualHelp
    {
        /// <summary>
        /// 获取所有的控件
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static List<DependencyObject> GetChildrens(DependencyObject parent)
        {
            int count = VisualTreeHelper.GetChildrenCount(parent);
            List<DependencyObject> dependencyObjects = new();
            for (int i = 0; i < count - 1; i++)
            {
                DependencyObject visual = VisualTreeHelper.GetChild(parent, i);
                dependencyObjects.Add(visual);
                if (VisualTreeHelper.GetChildrenCount(visual) != 0)
                {
                    dependencyObjects.AddRange(GetChildrens(visual));
                }
            }

            return dependencyObjects;
        }

        //public static IAvaloniaList<T> GetChildrens<T>(IVisual parent) where T : IVisual
        //{
        //    IAvaloniaList<T> lisChildrens = new AvaloniaList<T>();
        //    foreach (IVisual visual in parent.VisualChildren)
        //    {
        //        if (visual is T t)
        //        {
        //            lisChildrens.Add(t);
        //        }
        //        if (visual.VisualChildren.Count > 0)
        //        {
        //            IAvaloniaList<T> visuals = GetChildrens<T>(visual);
        //            lisChildrens.AddRange(visuals);
        //        }
        //    }
        //    return lisChildrens;
        //}
    }
}
